// 头部控制器（用户登录状态显示用户名及退出登录否则进入登录页）
define('headerController', ['angular'], function (angular) {
    var module = angular.module('controllers');
    module.controller('headerController', ['$scope','$rootScope','$location','loginServers', function ($scope,$rootScope,$location,loginServers) {
        $scope.checkUser=function(){
            var user=loginServers.getUser();
            if (!angular.equals({},user) && user) {
                $rootScope.$broadcast('user.login.success',user);
                $scope.user=user;
                $scope.hideUser=true;
            }else{
                $scope.hideUser=false;
            }
        };
        $scope.checkUser();
        $rootScope.$on('$routeChangeStart', function(event, currRoute, prevRoute){
            $scope.checkUser();
        });
        $scope.logout = function () {
            loginServers.logout();
            $scope.hideUser=false;
            $location.path("/login");
        };
    }]);
});